package com.tom.architect02.zframework.wms.skin.higher_lib.utils;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;

import com.tom.architect02.R;
import com.tom.architect02.zframework.wms.skin.higher_lib.SkinView;
import com.tom.architect02.zframework.wms.skin.higher_lib.ViewAttr;
import java.util.ArrayList;
import java.util.List;

public class SkinCollectManager {
    private List<SkinView> skinViews = new ArrayList<>();

    public void collectView(Context context, View currentView, AttributeSet attr) {
        List<ViewAttr> viewAttrList = new ArrayList<>();
        TypedArray typedArray = context.obtainStyledAttributes(attr, R.styleable.skin);
        boolean isChange = typedArray.getBoolean(R.styleable.skin_changeSkin, false);
        typedArray.recycle();
        if (!isChange)
            return;
        for (int i = 0; i < attr.getAttributeCount(); i++) {
            String attributeName = attr.getAttributeName(i);
            if (SkinFactory.mAttrName.contains(attributeName)) {
                String attributeValue = attr.getAttributeValue(i);
                if (attributeValue.startsWith("#")) {
                    continue;
                }
                int resId = Integer.parseInt(attributeValue.substring(1));
                //可以获取resourceName，resourceType
                String resourceName = context.getResources().getResourceEntryName(resId);

                ViewAttr viewAttr = new ViewAttr(attributeName, resId);
                viewAttrList.add(viewAttr);
            }
        }
        if (viewAttrList.size() > 0) {
            SkinView skinView = new SkinView(viewAttrList, currentView);
            skinViews.add(skinView);
        }
    }

}
